package cn.wind.xboot.logic.cli.service.impl;

import cn.wind.xboot.logic.cli.dao.CliInfoMapper;
import cn.wind.xboot.logic.cli.entity.CliInfo;
import cn.wind.xboot.logic.cli.service.ICliInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author xukk
 * @since 2018-08-13
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class CliInfoServiceImpl extends ServiceImpl<CliInfoMapper, CliInfo> implements ICliInfoService {
    @Override
    public CliInfo selectByCliId(Long cliId) {
        return getOne(new QueryWrapper<CliInfo>().lambda().eq(CliInfo::getCliId, cliId));
    }

    @Override
    public boolean updateMobile(Long cliId, String mobile) {
        CliInfo cliInfo = new CliInfo();
        cliInfo.setMobile("");
        if (update(cliInfo, new QueryWrapper<CliInfo>().lambda().eq(CliInfo::getMobile, mobile))) {
            cliInfo.setMobile(mobile);
            return update(cliInfo, new QueryWrapper<CliInfo>().lambda().eq(CliInfo::getCliId, cliId));
        } else {
            return false;
        }

    }

    @Override
    public IPage<CliInfo> findAll(IPage page, Map<String, Object> map) {
        return this.baseMapper.findAll(page,map);
    }

    @Override
    public int delById(Long id) {
        return this.baseMapper.delById(id);
    }
}
